package org.kuaishou;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.io.File;
import java.util.List;

public class Run_HuiRan {
    public static final String USER_DIR = System.getProperty("user.dir");
    String tableName = "hui_ran_video";
    String pyVideoRoot = "D:/ROOT/py_video/kuaishou_hui_ran";
    public static final String USER_ID = "3xz53hc7evacuys";

    //  "profileUserTopPhoto": true, 标识是否置顶
    @Test
    public void loadList() throws Exception {
        String url = "https://www.kuaishou.com/graphql";

        LoadVIdeoList load = new LoadVIdeoList();

        List<String> idList = load.loadList(url, tableName, USER_ID);
        String join = StringUtils.join(idList, "','");
        String ids = String.format("('%s')", join);
        System.out.println("本次新增:" + idList.size());

        final String find = "SELECT a.* FROM %s A WHERE A.`LOAD_TIME` IS NULL ORDER BY A.SORT DESC ;";
        final String sqlFM = "SELECT a.* FROM %s A \nWHERE A.ID IN %s \nORDER BY A.SORT DESC ";

        String printSQL = "\n" + String.format(find, tableName) + "\n\n" + String.format(sqlFM, tableName, ids) + "\n";
        System.out.println(printSQL);
        File file = FileUtils.getFile(USER_DIR, "res/SQL.TXT");
        FileUtils.writeStringToFile(file, printSQL, "UTF-8");
    }

    @Test
    public void load() throws Exception {
        LoadVIdeoList load = new LoadVIdeoList();
        load.loadVodeo(tableName, pyVideoRoot);
    }
}
